package chapter1.No1_7_停止线程.g使用return停止线程;

/**
 * return停止线程
 *
 * @author liujian
 * @version 2016/11/9 0009
 */
public class MyThreadReturn extends Thread {

    @Override
    public void run() {
        for(int i = 0; i < 50000; i++) {
            if(this.isInterrupted()) {
                System.out.println("线程中断我要使用return退出~");
                return ;
            }
            System.out.println(i);
        }
        System.out.println("我是循环以外的业务代码~");
    }

    public static void main(String[] args) throws InterruptedException {
        MyThreadReturn m1 = new MyThreadReturn();
        m1.start();
        Thread.sleep(100);
        m1.interrupt();
        System.out.println("END");
    }
}
